C_PRO := gcc

C_ARG := -g -DUNIX

D_INC := 

D_SRC := src

D_OBJ := obj

D_BIN := bin

F_SRC := $(wildcard $(D_SRC)/*.c)

F_OBJ := $(patsubst $(D_SRC)/%.c,$(D_OBJ)/%.o,$(F_SRC))

F_BIN := $(D_BIN)/booksys

.PHONY: clean

$(F_BIN): $(F_OBJ)
	@mkdir -m 770 -p $(D_BIN)
	$(C_PRO) -o $@ $^

$(D_OBJ)/%.o: $(D_SRC)/%.c
	@mkdir -m 770 -p $(D_OBJ)
	$(C_PRO) -o $@ $(C_ARG) -c $< $(addprefix -I,$(D_INC))

$(D_OBJ)/%.d: $(D_SRC)/%.c
	@mkdir -m 770 -p $(D_OBJ)
	@set -e; rm -f $@; $(C_PRO) -MM $< $(addprefix -I,$(D_INC)) > $@.$$$$; \
	sed 's,\($*\)\.o[ :]*,$(D_OBJ)/\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

-include $(F_OBJ:.o=.d)

clean:
	rm -rf $(F_BIN) $(D_OBJ)/*
